/**
 * 
 */
package fr.cie.blog.controller;

import java.util.List;

import fr.cie.blog.beans.Style;
import fr.cie.blog.domainservice.IServiceStyle;

/**
 * @author Jee3
 * 
 */
public class StyleAction extends GenericAction {

	/**
	 * serialVersionUID.
	 */
	private static final long serialVersionUID = 1006246041861450444L;
	/**
	 * style.
	 */
	private Style style;

	/**
	 * styleList.
	 */
	private List<Style> styleList;

	/**
	 * serviceStyle.
	 */
	private IServiceStyle serviceStyle;

	// implicit web properties

	/**
	 * Constructor.
	 * 
	 * @param pServiceStyle
	 *            serviceStyle
	 */
	public StyleAction(final IServiceStyle pServiceStyle) {
		super();
		serviceStyle = pServiceStyle;
	}

	/**
	 * @return the serviceStyle
	 */
	public final IServiceStyle getServiceStyle() {
		return serviceStyle;
	}

	/**
	 * @return the style
	 */
	public final Style getStyle() {
		return style;
	}

	/**
	 * @return the styleList
	 */
	public final List<Style> getStyleList() {
		return styleList;
	}

	/**
	 * @param pServiceStyle
	 *            the serviceStyle to set
	 */
	public final void setServiceStyle(final IServiceStyle pServiceStyle) {
		this.serviceStyle = pServiceStyle;
	}

	/**
	 * @param pStyle
	 *            the style to set
	 */
	public final void setStyle(final Style pStyle) {
		this.style = pStyle;
	}

	/**
	 * @param pstyleList
	 *            the styleList to set
	 */
	public final void setStyleList(final List<Style> pstyleList) {
		this.styleList = pstyleList;
	}

	/**
	 * @return SUCCESS
	 */
	public final String modifyPersonalStyle() {
	
		if (style == null) {
			// if style is not initialized, the default style is set.
			style = ((Style) getSession().get("currentStyle"));
	
		}
		LOG.trace("Change current style to : " + style);
		
		Style newStyle = serviceStyle.findById(style.getId());
		getSession().put("currentStyle", newStyle);
	
		return SUCCESS;
	}
}
